#include "logview.h"
#include "ui_logview.h"

LogView::LogView(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LogView)
{
    ui->setupUi(this);
    setWindowTitle("日志");
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    ui->tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: rgb(200, 255, 255);border: none;height:28px;}");
    DBOperate db;
    logsInfo = db.selectLogsInfo();
    ui->tableWidget->setRowCount(logsInfo.length());
    for (int i = 0; i < logsInfo.length(); i++)
    {
        LogInfo logInfo = logsInfo.at(i);
        QTableWidgetItem *item_1 = new QTableWidgetItem();
        item_1->setText(logInfo.nodeName);
        item_1->setFlags(item_1->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 0, item_1);
        QTableWidgetItem *item_2 = new QTableWidgetItem();
        item_2->setText(logInfo.affiliatedArea);
        item_2->setFlags(item_2->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 1, item_2);
        QTableWidgetItem *item_3 = new QTableWidgetItem();
        item_3->setText(logInfo.ID);
        item_3->setFlags(item_3->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 2, item_3);
        QTableWidgetItem *item_4 = new QTableWidgetItem();
        switch (logInfo.eventType)
        {
            case 0:
                item_4->setText("告警");
                break;
            case 1:
                item_4->setText("系统");
                break;
            case 2:
                item_4->setText("告警解除");
                break;
            case 3:
                item_4->setText("系统维护");
                break;
            default:
                break;
        }
        item_4->setFlags(item_4->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 3, item_4);
        QTableWidgetItem *item_5 = new QTableWidgetItem();
        item_5->setText(logInfo.eventDescription);
        item_5->setFlags(item_5->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 4, item_5);
        QTableWidgetItem *item_6 = new QTableWidgetItem();
        item_6->setText(logInfo.date);
        item_6->setFlags(item_6->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 5, item_6);
        QTableWidgetItem *item_7 = new QTableWidgetItem();
        item_7->setText(logInfo.op);
        item_7->setFlags(item_7->flags() & ~Qt::ItemIsEnabled & ~Qt::ItemIsSelectable);
        ui->tableWidget->setItem(i, 6, item_7);
    }
}

LogView::~LogView()
{
    delete ui;
}
